package kin.converter;



import java.lang.reflect.InvocationTargetException;

import kin.system.util.ApplicationContextHelper;
import kin.system.util.StringUtil;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.Converter;
import org.apache.commons.beanutils.MethodUtils;

public  class BeanTypeConverter implements Converter {
   
    
   

	public Object convert(Class arg0, Object arg1) {
		System.out.println("kkkkkkkkkkkkkkkkkk");
		String packageName=arg0.getPackage().getName();
		
			if(packageName.equals("kin.test")||packageName.equals("kin.bean.system")||packageName.equals("kin.bean.security")||packageName.equals("kin.bean.customer")){
				String value=(String)arg1;
				int id=0;
				if(value!=null&&!"".equals(value)){
				id=Integer.parseInt((String)arg1);
				System.out.println("arg1:"+id);
				Object o=null;
				
				try {
					 o=arg0.newInstance();
					 if(o!=null){
						 String IdField=StringUtil.fristLetterLowerCase(arg0.getSimpleName())+"_id";
					BeanUtils.copyProperty(o, IdField, id);
					 }
				} catch (InstantiationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return o;
				}
			}
		
		return null;
	}  
}  